#!/bin/bash

>open_web_pc.txt
>open_mysql_pc.txt
for i in {1..254}
do
        (nc -z 192.168.0.${i} 80 &>/dev/null
        if (($?==0))
        then
                echo 192.168.0.${i} >>open_web_pc.txt
        fi
        nc -z 192.168.0.${i} 3306 &>/dev/null
        if (($?==0))
        then
                echo 192.168.0.${i} >>open_mysql_pc.txt
	fi)&
done
sleep 1
a=`cat open_web_pc.txt|wc -l`
b=`cat open_mysql_pc.txt|wc -l`
#cat up.txt|sort -t "." -k 4 -n
echo -e "\e[31mhave $a computers open web service\e[0m"
#cat down.txt|sort -t "." -k 4 -n
echo -e "\e[33mhave $b computers open mysql service\e[0m"
